<template>
  <div class="input-number-range">
    <el-input-number class="input-number-range__item" v-model="xValue" placeholder="请输入"
      :precision="precision" :controls-position="controlsPosition"></el-input-number>
    <span class="input-number-range__separator">-</span>
    <el-input-number class="input-number-range__item" v-model="yValue" placeholder="请输入"
      :precision="precision" :controls-position="controlsPosition"></el-input-number>
  </div>
</template>

<script>
export default {
  name: 'InputNumberRange',
  props: {
    value: {
      type: Array,
      default: () => [0, 0]
    },
    precision: {
      type: Number,
      default: 0
    },
    'controlsPosition': {
      type: String,
      default: 'right'
    }
  },
  computed: {
    xValue: {
      get() {
        return (this.value || [])?.[0] || ''
      },
      set(val) {
        this.$emit('input', [val, this.value[1]])
      }
    },
    yValue: {
      get() {
        return (this.value || [])?.[1] || ''
      },
      set(val) {
        this.$emit('input', [this.value[0], val])
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.input-number-range {
  display: flex;
  align-items: center;

  &__separator {
    padding: 0 4px;
  }

  &__item {
    flex: 1;
  }
}
</style>
